package com.ttl.springboot.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ttl.springboot.entity.Category;
import com.ttl.springboot.mapper.CategoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 功能
 * 作者:江哥
 * 日期:2024/8/11 17:47
 */
@Service
public class CategoryService {
    @Autowired(required = false)
    private CategoryMapper categoryMapper;

    /*
     * 新增
     * */
    public void add(Category category) {
        categoryMapper.insert(category);
    }

    /*
     * 删除
     * */
    public void deleteById(Integer id) {
        categoryMapper.deleteById(id);
    }

    /*
     * 更新
     * */
    public void updateById(Category category) {
        categoryMapper.updateById(category);
    }

    /*
     * 查询单个
     * */
    public Category selectById(Integer id) {
        return categoryMapper.selectById(id);
    }

    /*
     * 查询所有
     * */
    public List<Category> selectAll(Category category) {
        return categoryMapper.selectAll(category);
    }

    /*
     * 分页查询
     * */
    public PageInfo<Category> selectPage(Category category, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Category> list = categoryMapper.selectAll(category);
        return PageInfo.of(list);
    }

    /*
     * 批量删除
     * */
    public void deleteBatch(List<Integer> ids) {
        for (Integer id : ids) {
            this.deleteById(id);
        }
    }
}
